/*
 * Lockable.h
 *
 *  Created on: 20/06/2014
 *      Author: Vitor
 */

#ifndef LOCKABLE_H_
#define LOCKABLE_H_

#include "SDL2/SDL.h"
#include "SDL2/SDL_thread.h"

template<typename T>
class Lockable {
private:
	T value;
	SDL_mutex* mutex;

public:
	Lockable(T value) :
			value(value) {
		mutex = SDL_CreateMutex();
	}
	virtual ~Lockable() {
		SDL_DestroyMutex(mutex);
	}

	void lock() {
		SDL_mutexP(mutex);
	}

	void unlock() {
		SDL_mutexV(mutex);
	}

	T& get() {
		return value;
	}
};

#endif /* LOCKABLE_H_ */
